package com.xinqi.modules.prepare.courseware.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.prepare.common.dto.data.PrepareCoursewareData;
import com.xinqi.modules.prepare.courseware.domain.PrepareCoursewareEntity;
import com.xinqi.modules.prepare.courseware.dto.req.PrepareCoursewareCreateDTO;
import com.xinqi.modules.prepare.courseware.dto.req.PrepareCoursewareUpdateDTO;
import com.xinqi.modules.prepare.courseware.dto.rsp.PrepareCoursewareResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 备课区互动课件转换
 *
 * @author: system
 * @date: 2023/03/19
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class PrepareCoursewareConvert {
    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareCoursewareEntity create(PrepareCoursewareCreateDTO s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareCoursewareEntity create(PrepareCoursewareData s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareCoursewareEntity update(PrepareCoursewareUpdateDTO s, @MappingTarget PrepareCoursewareEntity t);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareCoursewareEntity update(PrepareCoursewareUpdateDTO s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    public abstract PrepareCoursewareResultDTO convert(PrepareCoursewareEntity s);

    public abstract PrepareCoursewareData convert(PrepareCoursewareResultDTO s);

    public abstract PrepareCoursewareCreateDTO updateToCreate(PrepareCoursewareUpdateDTO s);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "prepareId", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "deleteTime", ignore = true)
    @Mapping(target = "isDelete", ignore = true)
    public abstract PrepareCoursewareEntity copy(PrepareCoursewareEntity entity, @MappingTarget PrepareCoursewareEntity prepareCoursewareEntity);

}
